﻿Public Class Form1
  Private Sub Button1_Click(
      ByVal sender As System.Object,
      ByVal e As System.EventArgs) _
      Handles Button1.Click
    esegui("A", "Z")
  End Sub
  Private Sub A_Click(
      ByVal sender As System.Object,
      ByVal e As System.EventArgs) _
      Handles A.Click
    esegui("A", "G")
  End Sub
  Private Sub B_Click(
      ByVal sender As System.Object,
      ByVal e As System.EventArgs) _
      Handles B.Click
    esegui("H", "P")
  End Sub
  Private Sub C_Click(
      ByVal sender As System.Object,
      ByVal e As System.EventArgs) _
      Handles C.Click
    esegui("Q", "Z")
  End Sub
  Private Sub esegui(
      ByVal daLettera As String,
      ByVal aLettera As String)
    Dim db As DataClasses1DataContext =
       New DataClasses1DataContext()
    Dim contatti =
      From c In db.Customers
      Where c.first_name.Substring(0, 1) >=
        daLettera And
        c.first_name.Substring(0, 1) <=
        aLettera
      Order By c.first_name, c.last_name
      Select c.first_name, c.last_name
    Me.DataGridView1.DataSource = contatti
  End Sub
End Class
